package Java.BlackHorse.Collections;

import java.util.ArrayList;
import java.util.Collections;

public class CollectionDemo2 {
    public static void main(String[] args) {
        System.out.println("-----sort默认规则-----");
        ArrayList<Integer> list1 =new ArrayList<>();
        Collections.addAll(list1,2,5,7,1,9,8,3,4);
        Collections.sort(list1);
        System.out.println(list1);

        System.out.println("-----sort指定规则-----");
        Collections.sort(list1, (o1, o2)-> o2-o1);//降序
//        Collections.sort(list1, (o2, o1)-> o2-o1);//升序
        System.out.println(list1);

        System.out.println("-----binarySearch二分查找-----");
        ArrayList<Integer> list2 = new ArrayList<>();
        Collections.addAll(list2,1,3,4,6,8,9,10,13);
        System.out.println(Collections.binarySearch(list2,3));
        System.out.println(Collections.binarySearch(list2,9));

        System.out.println("-----copy 集合a copy 集合b 中的内容-----");
        ArrayList<Integer> list3 = new ArrayList<>();
        ArrayList<Integer> list4 = new ArrayList<>();
        Collections.addAll(list3,2,4,6,8,10);
        Collections.addAll(list4,1,3,5,7,9);
//        Collections.copy(list3,list4);//list3 copy list4
        Collections.copy(list4,list3);//list4 copy list3
        System.out.println(list3);
        System.out.println(list4);

        System.out.println("-----fill 将集合中的所以数据都修改为指定数据-----");
        ArrayList<Integer> list5 = new ArrayList<>();
        Collections.addAll(list5,1,2,3,4,5,6,7,8);
        System.out.println(list5);
        Collections.fill(list5,666);
        System.out.println(list5);

        System.out.println("-----max/min 求最大最小值-----");
        ArrayList<Integer> list6 = new ArrayList<>();
        Collections.addAll(list6,1,2,3,4,5,6,7,8,9);
        System.out.println("最大值："+Collections.max(list6));
        System.out.println("最小值："+Collections.min(list6));

        System.out.println("-----swap 下标i和j的数据交换-----");
        ArrayList<Integer> list7 = new ArrayList<>();
        Collections.addAll(list7,1,2,3,4,5,6,7,8);
        Collections.swap(list7,0,2);
        System.out.println(list7);
    }
}
